/**
* Oxide
*
* Copyright (c) 2011 Dinosaur Kick Pty Ltd, All rights reserved.
*
* This source code is made available under the "Modified BSD" licensing arrangement.
* See license.txt for details.
*/
// ----------------------------------------------------------------------------
#include <cassert>
#include "../token.hpp"
#include "../cursor.hpp"
#include "cursor_incrementer.hpp"
#include "iterator.hpp"
#include "keyword_map.hpp"
// ----------------------------------------------------------------------------
#ifndef O2_LEX_LEXER_INC
#define O2_LEX_LEXER_INC
namespace o2 {
namespace lex {
// ----------------------------------------------------------------------------

template <typename IteratorT, typename StringT = std::basic_string<typename std::iterator_traits<IteratorT>::value_type> >
class basic_lexer
{
	public:
		typedef IteratorT input_iterator_type;
		typedef StringT string_type;
		typedef typename string_type::value_type char_type;
		typedef iterator<basic_lexer<input_iterator_type, string_type> > iterator;
		typedef cursor<input_iterator_type, detail::cursor_incrementer<input_iterator_type> > cursor_type;
		typedef basic_token<string_type> token_type;
		typedef basic_keyword_map<string_type> keyword_map_type;
		
		basic_lexer(const input_iterator_type& begin, const input_iterator_type& end)
			: m_cursor(begin, end)
			{ }

		bool advance(void)
			{ return m_cursor.skip_empty() && dispatch_primaries(); }

		const token_type& current(void) const
			{ return m_token; }

		iterator begin(void)
			{ return iterator(*this); }

		iterator end(void)
			{ return iterator(); }

	private:
		#include "lexer_token.ipp"
		#include "lexer_primaries.ipp"
		#include "lexer_comments.ipp"
		#include "lexer_identifier.ipp"
		#include "lexer_numeric.ipp"
		#include "lexer_string.ipp"

		cursor_type m_cursor;
		token_type m_token;
		keyword_map_type m_keyword_map;
};

// ----------------------------------------------------------------------------
} // namespace lex
} // namespace o2
#endif // O2_LEX_LEXER_INC
// ----------------------------------------------------------------------------
